package org.example.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.pojo.Student;
import org.example.pojo.StudentQueryParam;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    /**
     * 学员列表分页查询
     * @param studentQueryParam
     * @return
     */
    Page<Student> pageQuery(StudentQueryParam studentQueryParam);

    /**
     * 新增学员
     * @param student
     */
    void insert(Student student);

    /**
     * 根据id查询学员
     * @param id
     * @return
     */
    @Select("select * from student where id=#{id}")
    Student selectById(Integer id);

    /**
     * 修改学员信息
     * @param student
     */
    void update(Student student);

    /**
     * 根据id批量删除学员
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据班级id，统计各班级人数
     * @param clazzId
     */
    @Select("select count(*) from student where clazz_id= #{clazzId}")
    Integer selectGroupByClazzId(Integer clazzId);

    /**
     * 统计各学历人数
     * @return
     */
    @MapKey("name")
    List<Map> selectGroupByDegree();

    /**
     * 根据班级id查询学员列表
     * @param id
     * @return
     */
    @Select("select * from student where clazz_id= #{id}")
    List<Student> selectByClazzId(Integer id);
}
